#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: zhangZW
@file: CheckMiddleware.py
@time: 2022/11/16
@des: description
"""
from django.utils.deprecation import MiddlewareMixin
# from apps.users.models import User
from django.shortcuts import redirect, render
from CloudPlatform import settings


class CheckMiddleware(MiddlewareMixin):

    def process_request(self, request):
        session_id = request.COOKIES.get(settings.SESSION_COOKIE_NAME)
        if request.path == '/' or request.path.startswith('/login') or request.path.startswith('/static') or \
                request.path == '/client/register/':
            pass
        else:
            if request.session.exists(session_id):
                pass
            else:
                return redirect('/')
